function contains_text(element, text){
    return element.querySelector('.title').textContent.toLowerCase().includes(text) || element.querySelector('.student').textContent.toLowerCase().includes(text);
}

function match_group(element, group){
    if (group == "Не указано"){
        return true;
    }
    return element.querySelector('.student-group').textContent == group;
}

function match_type(element, type){
    if (type == "Не указано"){
        return true;
    }
    return element.querySelector('.project-type').textContent == type;
}


function block_open(project_id, el) {
    let project = document.getElementById(project_id);

    if ($(project).hasClass('block-open')) {
        $(project).removeClass('block-open');
        $(el).html('Подробнее');
    } else {
        $(project).addClass('block-open');
        $(el).html('Скрыть');
    }
}

function filters_open(btn) {
    let div = btn.parentNode;
    let content = div.querySelector('.filters-content');
    let svg = btn.querySelector('.filters-svg');
    if ($(content).hasClass('list-hidden')) {
        $(content).removeClass('list-hidden');
        $(svg).css({'transform' : 'rotate(0deg)'});
        if (content.scrollHeight > 250) {
            $(content).css({'height' : '250px'});
        } else {
            $(content).css({'height' : content.scrollHeight + 'px'});
        }
    } else {
        $(content).addClass('list-hidden');
        $(svg).css({'transform' : 'rotate(45deg)'});
    }
}

function filters_search(input) {
    let text = input.value.trim();
    let content = input.parentNode.parentNode
    let list = content.querySelectorAll('.filters-item');
    for (let i = 1; i < list.length; i++) {
        let item_text = list[i].querySelector('.filters-text').textContent;
        if (item_text.toLowerCase().match(text.toLowerCase()) || text == '') {
            $(list[i]).removeClass('hidden');
        } else {
            $(list[i]).addClass('hidden');
        }
    }
    if (content.scrollHeight > 250) {
            $(content).css({'height' : '250px'});
        } else {
            $(content).css({'height' : content.scrollHeight + 'px'});
        }
}

function filters_clear(btn) {
    let input = btn.parentNode.querySelector('.filters-input');
    input.value = '';
    filters_search(input);
}

function search_input_update(input) {
    let value = input.value;
    $('.filters-search-input').val(value);
}